package com.ruoyi.yuyuan.Controller;

import com.ruoyi.yuyuan.DTO.BlogAgreementDTO;
import com.ruoyi.yuyuan.DTO.Result;
import com.ruoyi.yuyuan.Entity.BlogAgreement;
import com.ruoyi.yuyuan.Service.IAgreementBlogService;
import com.ruoyi.yuyuan.Utils.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/5/29
 */
@RestController
@RequestMapping("/agreementBlog")
public class AgreementBlogController {
    @Autowired
    private IAgreementBlogService agreementBlogService;

    //发布约球贴
    @PostMapping("/publish/{blogType}")
    public Result publishAgreement(@RequestBody BlogAgreementDTO blogAgreementDTO, @PathVariable Short blogType) throws InterruptedException {
        return agreementBlogService.publishAgreement(blogAgreementDTO,blogType);
    }

    //更新约球贴
    @PostMapping("/update/{blogId}")
    public Result updateAgreement(@RequestBody BlogAgreementDTO blogAgreementDTO, @PathVariable Long blogId) throws InterruptedException {
        return agreementBlogService.updateAgreement(blogAgreementDTO,blogId);
    }

    //获取约球贴
    @GetMapping("/{blogType}/{blogId}")
    public  Result getSingleAgreement(@PathVariable Short blogType,@PathVariable Long blogId){
        return agreementBlogService.getSingleAgreement(blogType,blogId);
    }

    //分页查询约球贴
    @GetMapping("/page/{blogType}/{startId}")
    public Result getAgreement(@PathVariable Short blogType, @PathVariable Long startId){
        return agreementBlogService.getAgreement(blogType,startId);
    }

    //搜索约球帖子
    @GetMapping("/SearchAgreements/{searchKeyWord}/{type}/{blogType}")
    public Result getSearchAgreements(@PathVariable String searchKeyWord, @PathVariable Short type, @PathVariable Short blogType) throws IOException {
        return agreementBlogService.getSearchAgreements(searchKeyWord, type, blogType);
    }
}
